<?php

namespace Form;

use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\PostApi;
use Yj\ColumnBuilder\Column;
use Yj\Form\Elm;

/**
 * @ApiController(prefix="form/activity")
 */
class Activity
{   

    protected $routes = [
        'lists'=>'/admin/activity/activity/lists',
        'add'=>'admin/activity/activity/add',
        'form'=>'/form/activity/update',
    ];

    public function getColumn(){
        $colum = Column::create();
        $colum->setRules([
            Column::txt()->setLabel('标题')->setProp('title'),
            Column::txt()->setLabel('标题')->setProp('title'),
        ]);
        return $colum->toArray();
    }

    protected function getRoute($types=null){
        if(is_null($types)){
            return $this->routes;
        }
        return $this->routes[$types];
    }

    /**
     * @PostApi(path="config",description="配置")
     */
    public function config(){
       $routes =  $this->getRoute();
       $column = $this->getColumn();
       _SUCCESS(compact('routes','column'));
    }

    /**
     * @PostApi(path="update",description="添加")
     */
    public function update(){
        $form =  Elm::createForm($this->getRoute('add'));
        $form->setRule([
            Elm::input('title','活动名称')->required(),
        ]);
        $lists = $form->setTitle('添加活动')->formData([]);
        _SUCCESS(formToData($lists));
    }



}